package cn.ithers.blog.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Author: zhanghuan
 * @date: 2020/8/27 17:02
 * @description:
 */

@Data
public class ResponseResult {

    @ApiModelProperty(value = "响应消息")
    private String message;
    @ApiModelProperty(value = "响应是否成功")
    private boolean success;
    @ApiModelProperty(value = "响应码")
    private int status;
    @ApiModelProperty(value = "响应数据")
    private Object data;

    public ResponseResult(ResponseState responseState) {

        this.message = responseState.getMessage();
        this.success = responseState.isSuccess();
        this.status = responseState.getStatus();
    }

    public static ResponseResult GET(ResponseState state) {
        return new ResponseResult(state);

    }

    // 操作成功
    public static ResponseResult SUCCESS() {
        return new ResponseResult(ResponseState.SUCCESS);
    }
    public static ResponseResult ACCOUNT_NOT_LOGIN() {
        return new ResponseResult(ResponseState.ACCOUNT_NOT_LOGIN);
    }
    public static ResponseResult PERMISSION_DENIED() {
        return new ResponseResult(ResponseState.PERMISSION_DENIED);
    }
    public static ResponseResult ERROR_404() {
        return new ResponseResult(ResponseState.ERROR_404);
    }
    public static ResponseResult ERROR_405() {
        return new ResponseResult(ResponseState.ERROR_405);
    }
    public static ResponseResult ERROR_403() {
        return new ResponseResult(ResponseState.ERROR_403);
    }
    public static ResponseResult ERROR_500() {
        return new ResponseResult(ResponseState.ERROR_500);
    }
    public static ResponseResult ERROR_504() {
        return new ResponseResult(ResponseState.ERROR_504);
    }
    public static ResponseResult ERROR_505() {
        return new ResponseResult(ResponseState.ERROR_505);
    }
    public static ResponseResult WAiTING_FOR_SCAN() {
        return new ResponseResult(ResponseState.WAiTING_FOR_SCAN);
    }

    //重载
    public static ResponseResult SUCCESS(String message) {
        ResponseResult responseResult = new ResponseResult(ResponseState.SUCCESS);
        responseResult.setMessage(message);

        return responseResult;
    }

    // 操作失败
    public static ResponseResult FAILED() {
        return new ResponseResult(ResponseState.FAILED);
    }

    public static ResponseResult FAILED(String message) {

        ResponseResult responseResult = new ResponseResult(ResponseState.FAILED);
        responseResult.setMessage(message);
        return responseResult;

    }


    public static ResponseResult ACCOUNT_DENIED() {
        return new ResponseResult(ResponseState.ACCOUNT_DENIED);
    }



    public ResponseResult setData(Object data) {
        this.data = data;
        return this;
    }
}
